package com.jysz.certificate.utils;


import javax.servlet.ServletContext;
import javax.servlet.jsp.PageContext;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.jysz.webcore.ssh.web.struts.menu.MenuPermissionAdaptor;

/**
 * @author <a href="mailto:javaengine@outlook.com">Kaca Rich</a>
 *
 */
public class MenuUtil {
	private static final Logger LOG =  LoggerFactory.getLogger(MenuUtil.class);
	
	public static void  saveMenuPermissionAdaptor(PageContext pageContext){
		ServletContext sc = pageContext.getServletContext();
		ApplicationContext axc =  WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
		try{
			//TODO:这个beanName写入到config.properties
			Object obj = axc.getBean("menuPermissionAdaptor");
			if(obj instanceof MenuPermissionAdaptor){
				MenuPermissionAdaptor customAdaptor = (MenuPermissionAdaptor)obj;
				pageContext.setAttribute("menuPermissionAdaptor", customAdaptor);
			}else{
				LOG.error("menuPermissionAdaptor not found.");
			}
			
		}catch(Exception e){
			LOG.error("menuPermissionAdaptor not found.", e);
		}
		
	}
}
